using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows;
using System.Xml.Serialization;
using DeSleeper.Client.WakeOnLanService;

namespace DeSleeper.Client.WakeUp
{
    [Serializable]
    [XmlInclude(typeof(LocalWakeUpMethod))]
    [XmlInclude(typeof(HostNameWakeUpMethod))]
    [XmlInclude(typeof(MacAddressWakeUpMethod))]
    public abstract class WakeUpMethod : TargetComputerAttachable
    {
        public WakeUpMethod() {}
        public WakeUpMethod(TargetComputer target) : base(target) {}

        /// <summary>
        /// Does the assigned target have enough and correct information to perform a wake
        /// up with this method?
        /// </summary>
        public virtual bool IsValid { get { return (Target != null); } }

        /// <summary>
        /// A description of the target used to identify it to the user.
        /// </summary>
        public abstract string Description { get; }
        
        /// <summary>
        /// Identifier used to identify target to code.
        /// </summary>
        public abstract string Id { get; }

        /// <exception cref="InvalidOperationException">Wake Up method must be attached to a target to perform a wake up.</exception>
        public void WakeUp(WakeUpServiceClient serviceClient)
        {
            if (Target == null)
                throw new InvalidOperationException("Wake Up method must be attached to a target to perform a wake up.");

            WakeUpCore(serviceClient);
        }

        protected abstract void WakeUpCore(WakeUpServiceClient serviceClient);
    }
}